<?php
/**
* Letterman Newsletter Component
* 
* @package Letterman
* @author Soeren
* @copyright Soeren Eberhardt <soeren@virtuemart.net>
*   (who just needed an easy and *working* Newsletter component for Mambo 4.5.1 and mixed up Newsletter and YaNC)
* @copyright Mark Lindeman <mark@pictura-dp.nl> 
*    (parts of the Newsletter component by Mark Lindeman; Pictura Database Publishing bv, Heiloo the Netherland)
* @copyright Adam van Dongen <adam@tim-online.nl>
*    (parts of the YaNC component by Adam van Dongen, www.tim-online.nl)
*    
* @copyright Philip Sylvain <contact@sphilip.com>
*  	(MVC refactorization and AJAX)
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
*
*/

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();

jimport('joomla.application.component.controller');

class LettermanControllerConfig extends JController
{
	/**
	 * Custom Constructor
	 */
	function __construct( $default = array() )
	{
		// Set a default view if none exists
		if ( ! JRequest::getCmd( 'view' ) ) {
			
			JRequest::setVar('view', 'config' );
		}
		
		parent::__construct( $default );
		
		$this->registerTask( 'default', 'restore_default' );
	}
	
	function save()
    {

        $general    = JRequest::getVar( 'general'    , array() , 'POST' , 'array' );
        $methods = JRequest::getVar( 'methods' , array() , 'POST' , 'array' );
        
        $config = array_merge( $general, $methods);

        $component =& JComponentHelper::getComponent('com_letterman');
        
        $t_component =& JTable::getInstance('component');
        $t_component->load( $component->id );
        $t_component->bind( array('params'=> $config ));

        $redirectLink = 'index.php?option=com_letterman&controller=config' ;
        $this->setRedirect( $redirectLink );
        
        if ( !$t_component->store() ) {
            
            JError::raiseWarning( 200, 'Erreur d\'ecriture' );//TODO:traduire
           
            
        } else {
            
            $msg = "Configuration bien enregistree" ; //TODO:traduire
			$this->setRedirect( $redirectLink , $msg );
        }
        
    }
    
    
    /**
     * Restore default configuration
     *
     */
    function restore_default()
    {
		$component =& JComponentHelper::getComponent('com_letterman');

        $t_component =& JTable::getInstance('component');
       
        $t_component->load( $component->id );
        $t_component->params='';       
        
        
        $redirectLink = 'index.php?option=com_letterman&controller=config' ;
        $this->setRedirect( $redirectLink );
        
        if ( !$t_component->store() ) {
            
            JError::raiseWarning( 200, 'Erreur' );//TODO:traduire
           
            
        } else {
            
            $msg = "Configuration par defaut restauree" ; //TODO:traduire
			$this->setRedirect( $redirectLink , $msg );
        }

    }
	
}

